//
//  WebViewController.swift
//  WBSwift
//
//  Created by 贺瑞 on 2017/8/3.
//  Copyright © 2017年 herui. All rights reserved.
//

import UIKit
import SVProgressHUD

class WebViewController: UIViewController, UIWebViewDelegate {

    @IBOutlet weak var webView: UIWebView!
    
    var urlString : String?
    
     init(url : String) {
        super.init(nibName: "WebViewController", bundle: nil)
        self.urlString = url
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        if let urlString = urlString {
            if let url = URL(string:urlString){
                webView.loadRequest(URLRequest(url:url))
            }
        }
    }
    
}

extension WebViewController {
    
    func webViewDidStartLoad(_ webView: UIWebView) {
        SVProgressHUD.show()
    }
    func webViewDidFinishLoad(_ webView: UIWebView) {
        SVProgressHUD.dismiss()

        title = webView.stringByEvaluatingJavaScript(from: "document.title")
    }
    func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
        SVProgressHUD.dismiss()
    }

    
    
}
